import functools

from flask import current_app
from flask import session, g

from info.models import User


def do_index_class(index):
    if index == 1:
        return 'first'
    elif index == 2:
        return 'second'
    elif index == 3:
        return 'third'
    return ""


def user_login_data(f):
    @functools.wraps(f)
    def wrapper(*args,**kwargs):
        user_id = session.get('user_id', None)
        user = None
        if user_id:
            # 查询到用户后，查询该用户的数据
            try:
                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.debug('e')
        g.user = user
        return f(*args,**kwargs)
    return wrapper


